package com.zy.controller;

import lombok.Data;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author LittleDesire
 * @description
 * @date 2022-03-31 周四 15:20
 * @since 17
 */
@Controller
public class TestController {
    @RequestMapping
    public String t1() {
        return "home";
    }

    @Data
    static class User {
        int id;
        String name;
    }

    @RequestMapping("/api/show")
    @ResponseBody
    public Map<String, Object> show(User user, HttpServletRequest req) {
        System.out.println(user);
        System.out.println(req.getMethod());
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("method", req.getMethod());
        map.put("ip", req.getRemoteAddr());
        map.put("data", user);
        return map;
    }
}
